<?php namespace Common\Model;
/*
 * 轮播图控制器
 * 
 * */
	use \Hdphp\Model\Model;
	class shuffling extends Model
	{
		protected $table = "shuffling";//连接表
		//自动验证
		protected $validate = array();
		//自动完成
		protected $auto = array(
			array("sendtime","time","function",3,1),
			array("thumb","t_image","method",3,3),
		);
		
		//t_image获得缩略图
		protected function t_image()
		{
			if(isset($_POST['thumb'])){
				return $_POST["thumb"];
			}
			$path = "Upload/lunbo/"; 
			$file = Upload::path($path)->type("jpg,png")->size(2000000)->make();
			if($file){
				$thumbimg = Image::thumb($file[0]['path'],"Upload/lunbo/thumb/".$file[0]['basename'],1903,360,5);
				return $thumbimg;
			}else{
				return '';
			}
		}
		
		/*
		 * addlunbo  添加轮播
		 * */
		public function addlunbo()
		{
			//p($_FILES);die;
			if(!$this->create()) return FALSE;
			//执行添加
			return $this->add();
		}
		/*
		 * 编辑轮播
		 * */
		public function resetlunbo($lun_id)
		{
			if(!$this->create()) return FALSE;
			//
			if(isset($_FILES["thumb"]) && $_FILES['thumb']['error']==4){
				$this->error="请上传图片";
				return FALSE;
			}
			//
			return $this->where("lun_id",$lun_id)->save();
		}
		/*
		 * del  删除
		 * */
		public function del($lun_id){
			return $this->where("lun_id",$lun_id)->delete();
		}
	}
